<?php

class auth extends CI_Controller {
    /*
      Project     : 48c6c450f1a4a0cc53d9585dc0fee742
      Created on  : Mar 16, 2013, 11:29:15 PM
      Author      : Truong Khuong - khuongxuantruong@gmail.com
      Description :
      Purpose of the stylesheet follows.
     */

    function __construct() {
        parent::__construct();
        $this->smarty = new CI_Smarty3();
        $this->smarty->error_reporting = E_ALL & ~E_NOTICE;
    }

    function index() {
        $_SESSION["auth"]["privileges"] = array(
            "guide" => array("name" => "category")
        );
        echo "auth form";
    }

    function location() {
        $state = '';
        if (isset($_GET["state"]))
            $state = $_GET["state"];
        redirect($state);
    }

    function denied() {
        //echo "Access denied .";
        $this->smarty->display("backend/auth/02_access_denied");
    }

    function login() {
        $state = (isset($_GET["state"]) and $_GET["state"] != "") ? $_GET["state"] : "backend/";
        if (isset($_SESSION["auth"]["user"])) {
            redirect("$state");
        }
        if (!isset($_SESSION['auth']['oauth'])) {
            //redirect(base_url('OAuth')."?state=$state");
        }
        $this->smarty->display("backend/auth/01_login");
    }

    function logout() {
        unset($_SESSION["auth"]);
        $state = (isset($_GET["state"]) and $_GET["state"] != "") ? $_GET["state"] : "backend/auth/login";
        redirect("$state");
    }
    function exc_login() {
        //$_POST["username"]="icarus12345";
        //$_POST["password"]="V9ZXr6Uw";
        $this->load->module("backend/auth_backend");
        $R = $this->auth_backend->check_login();
        //$R['message']=$_POST['username'];
        $this->output->set_header('Content-type: application/json');
        $this->output->set_output(json_encode($R));
    }
}

?>